//
//  V_LoginViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/11/3.
//  Copyright © 2020 王洋. All rights reserved.
//

#import <AlipaySDK/AlipaySDK.h>
#import "JVERIFICATIONService.h"
#import "SDCycleScrollView.h"

#import "TTUDIDManager.h"
#import "UIView+Tools.h"

#import "GradualChangeTransition.h"

#import "V_LoginBannerCell.h"

#import "ForgetPswViewController.h"
#import "BindPhoneNumViewController.h"
#import "OpenInstallSDK.h"

#import "V_LoginViewController.h"
#import "LoginViewController.h"

@interface V_LoginViewController ()<SDCycleScrollViewDelegate, UINavigationControllerDelegate>

@property (nonatomic, strong) SDCycleScrollView *bannerView;

@property (nonatomic, strong) NSMutableArray *configArray;

@property (nonatomic, strong) NSMutableArray <LoginBannerModel *>*bannerArray;

@property (nonatomic, assign) NSInteger currentIndex;
@property (weak, nonatomic) IBOutlet UIButton *vloginBtn;

@end

@implementation V_LoginViewController

- (void)dealloc{
    self.navigationController.delegate = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];

    [self prepareData];
    //[self request_loginBanner];
    //[self countLoginAction:nil];
}

- (void)prepareData {
    
    self.bannerArray = @[].mutableCopy;
    NSMutableArray *imgArray = @[].mutableCopy;
    
    NSString *key = [self deviceType];//根据机型获取url
    for (NSDictionary *dic in self.configArray) {
        NSString *type = [dic valueForKey:@"type"];
        if ([type isEqualToString:key]) {
            NSMutableArray * imgCfgArray = [dic valueForKey:@"imgCfgArray"];
            for (NSDictionary *cgfDic in imgCfgArray) {
                LoginBannerModel *model = [LoginBannerModel modelWithDictionary:cgfDic];
                [imgArray addObject:model.bgImageUrl];
                [self.bannerArray addObject:model];
            }
        }
    }
    self.bannerView.imageURLStringsGroup = imgArray;

}

- (NSString *)deviceType {
        NSInteger height = TTScreenHeight;
        NSString *midStr = @"";
        switch (height) {
            case 480:
                midStr = @"_x1";
                break;
            case 568:
                midStr = @"_x2";
                break;
            case 667:
                midStr = @"_x3";
                break;
            case 736:
                midStr = @"_x4";
                break;
            case 812:
                midStr = @"_x5";
                break;
            case 896:
                midStr = @"_x6";
                break;
            default:
                midStr = @"_x6";
                break;
        }
    return midStr;;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.phoneLoginBtn pp_clipCorners:UIRectCornerAllCorners radius:self.phoneLoginBtn.frame.size.height/2 border:0.5 color:UIColor.clearColor];
    });
}

- (void)initView {
    
    [UIApplication sharedApplication].idleTimerDisabled = YES;
    self.navigationController.navigationBarHidden = YES;
    #if RT_INTERACTIVE_PUSH
        self.rt_navigationController.rt_enableInteractivePush = YES;
    #endif
    
    [JVERIFICATIONService preLogin:3 completion:^(NSDictionary *result) {
        
    }];
    
    [self.bannerBGView addSubview:self.bannerView];
    
    [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(0);
    }];
    
    self.bgImageView.alpha = 0.5;
    [UIView animateWithDuration:0.5 animations:^{
        self.bgImageView.alpha = 1;
    }];
    
    self.bannerBGView.alpha = 0;
    [UIView animateWithDuration:1 animations:^{
        self.bannerBGView.alpha = 1;
    }];
}

- (void)customWindow{
    JVUIConfig *config = [[JVUIConfig alloc] init];
    config.navCustom = YES;
    config.autoLayout = YES;
    config.modalTransitionStyle =  UIModalTransitionStyleCrossDissolve;
    config.agreementNavReturnImage = [UIImage imageNamed:@"close"];

    //弹框
    config.showWindow = YES;

    config.windowBackgroundAlpha = 0.3;
    config.windowCornerRadius = 6;

    config.sloganTextColor = [UIColor colorWithRed:187/255.0 green:188/255.0 blue:197/255.0 alpha:1/1.0];
    config.privacyComponents = @[@"同意《",@"",@"",@"》并授权极光认证Demo获取本机号码"];
    CGFloat windowW = 320;
    CGFloat windowH = 250;
    JVLayoutConstraint *windowConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    JVLayoutConstraint *windowConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];

    JVLayoutConstraint *windowConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:windowW];
    JVLayoutConstraint *windowConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:windowH];
    config.windowConstraints = @[windowConstraintY,windowConstraintH,windowConstraintX,windowConstraintW];

    JVLayoutConstraint *windowConstraintW1 = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:480];
    JVLayoutConstraint *windowConstraintH1 = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:250];


    config.windowHorizontalConstraints =@[windowConstraintY,windowConstraintH1,windowConstraintX,windowConstraintW1];

    //弹窗close按钮
    UIImage *window_close_nor_image = [UIImage imageNamed:@"public_close_black"];
    UIImage *window_close_hig_image = [UIImage imageNamed:@"public_close_black"];
    if (window_close_nor_image && window_close_hig_image) {
        config.windowCloseBtnImgs = @[window_close_nor_image, window_close_hig_image];
    }
    CGFloat windowCloseBtnWidth = 30;
    CGFloat windowCloseBtnHeight = 30;
    JVLayoutConstraint *windowCloseBtnConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeRight multiplier:1 constant:-5];
    JVLayoutConstraint *windowCloseBtnConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeTop multiplier:1 constant:5];
    JVLayoutConstraint *windowCloseBtnConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:windowCloseBtnWidth];
    JVLayoutConstraint *windowCloseBtnConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:windowCloseBtnHeight];
    config.windowCloseBtnConstraints = @[windowCloseBtnConstraintX,windowCloseBtnConstraintY,windowCloseBtnConstraintW,windowCloseBtnConstraintH];


    //logo
    config.logoImg = [UIImage imageNamed:@"loginLogo"];
    CGFloat logoWidth = 60;
    CGFloat logoHeight = 60;
    JVLayoutConstraint *logoConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    JVLayoutConstraint *logoConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeTop multiplier:1 constant:20];
    JVLayoutConstraint *logoConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:logoWidth];
    JVLayoutConstraint *logoConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:logoHeight];
    config.logoConstraints = @[logoConstraintX,logoConstraintY,logoConstraintW,logoConstraintH];

    JVLayoutConstraint *logoConstraintLeft = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeLeft multiplier:1 constant:16];

    JVLayoutConstraint *logoConstraintTop = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeTop multiplier:1 constant:11];

    config.logoHorizontalConstraints = @[logoConstraintLeft,logoConstraintTop,logoConstraintW,logoConstraintH];


    //号码栏
    JVLayoutConstraint *numberConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    JVLayoutConstraint *numberConstraintY = [JVLayoutConstraint constraintWithAttribute: NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemLogo attribute:NSLayoutAttributeBottom multiplier:1 constant:14];

    JVLayoutConstraint *numberConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:28];
    JVLayoutConstraint *numberConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:200];

    JVLayoutConstraint *numberConstraintY1 = [JVLayoutConstraint constraintWithAttribute: NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemLogo attribute:NSLayoutAttributeBottom multiplier:1 constant:39];

    config.numberConstraints = @[numberConstraintX,numberConstraintY,numberConstraintH,numberConstraintW];
    config.numberHorizontalConstraints = @[numberConstraintX,numberConstraintY1,numberConstraintH,numberConstraintW];

    //slogan展示
    JVLayoutConstraint *sloganConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    JVLayoutConstraint *sloganConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNumber attribute:NSLayoutAttributeBottom   multiplier:1 constant:4];
    JVLayoutConstraint *sloganConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:17];
    JVLayoutConstraint *sloganConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:200];

    config.sloganConstraints = @[sloganConstraintX,sloganConstraintY,sloganConstraintW,sloganConstraintH];

    //登录按钮
    UIImage *login_nor_image = [UIImage imageNamed:@"btn_38px"];
    UIImage *login_dis_image = [UIImage imageNamed:@"btn_38px_ull"];
    UIImage *login_hig_image = [UIImage imageNamed:@"btn_38px"];
    if (login_nor_image && login_dis_image && login_hig_image) {
        config.logBtnImgs = @[login_nor_image, login_dis_image, login_hig_image];
    }
    config.logBtnText = @"一键登录";
    CGFloat loginButtonWidth = 220;
    CGFloat loginButtonHeight = 38;
    JVLayoutConstraint *loginConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    JVLayoutConstraint *loginConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSlogan attribute:NSLayoutAttributeBottom multiplier:1 constant:10];
    JVLayoutConstraint *loginConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:loginButtonWidth];
    JVLayoutConstraint *loginConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:loginButtonHeight];
    JVLayoutConstraint *loginConstraintY1 = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSlogan attribute:NSLayoutAttributeBottom multiplier:1 constant:13];
    config.logBtnConstraints = @[loginConstraintX,loginConstraintY,loginConstraintW,loginConstraintH];
    config.logBtnHorizontalConstraints = @[loginConstraintX,loginConstraintY1,loginConstraintW,loginConstraintH];
    //勾选框
    config.checkViewHidden = YES;
    //隐私
    config.privacyState = YES;
    config.privacyTextFontSize = 10;
    config.privacyTextAlignment = NSTextAlignmentCenter;
    config.appPrivacyColor = @[[UIColor colorWithRed:187/255.0 green:188/255.0 blue:197/255.0 alpha:1/1.0],[UIColor colorWithRed:137/255.0 green:152/255.0 blue:255/255.0 alpha:1/1.0]];
    JVLayoutConstraint *privacyConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    JVLayoutConstraint *privacyConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:180];
    JVLayoutConstraint *privacyConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeBottom multiplier:1 constant:-21];
    JVLayoutConstraint *privacyConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:32];
    JVLayoutConstraint *privacyConstraintY1 = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeBottom multiplier:1 constant:-23];
    JVLayoutConstraint *privacyConstraintH1 = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:14];
    JVLayoutConstraint *privacyConstraintW1 = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:400];
    config.privacyConstraints = @[privacyConstraintX,privacyConstraintY,privacyConstraintH,privacyConstraintW];
    config.privacyHorizontalConstraints = @[privacyConstraintX,privacyConstraintY1,privacyConstraintH1,privacyConstraintW1];
    //loading
    JVLayoutConstraint *loadingConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    JVLayoutConstraint *loadingConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
    JVLayoutConstraint *loadingConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:30];
    JVLayoutConstraint *loadingConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:30];
    config.loadingConstraints = @[loadingConstraintX,loadingConstraintY,loadingConstraintW,loadingConstraintH];

    [JVERIFICATIONService customUIWithConfig:config customViews:^(UIView *customAreaView) {

    }];

}

- (void)removLoading{
    [UIView removeLoadingAnimation];
}


- (IBAction)backAction:(id)sender {
    [self.navigationController dismissViewControllerAnimated:NO completion:nil];
    [[TT_TabbarViewController shareTabbar] setCurrentIndex:TT_TabbarIndexType_Home];

}


- (IBAction)V_LoginAction:(id)sender {
    self.vloginBtn.enabled = NO;
    BOOL isSetupClient = [JVERIFICATIONService isSetupClient];
    if (isSetupClient) {
    //初始化完成，可以进行后续操作

        if(![JVERIFICATIONService checkVerifyEnable]) {
            NSLog(@"当前网络环境不支持认证！");
            self.vloginBtn.enabled = YES;
            [SVProgressHUD showErrorWithStatus:@"当前网络环境不支持认证\n请关闭Wifi\n使用运营商3G/4G/5G"];
            [SVProgressHUD dismissWithDelay:3];
            return;
        }
        //继续获取token操作
        [self customWindow];
        
        [UIView loadingAnimation];
                
        [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(removLoading) userInfo:nil repeats:NO];
        
        WEAKSELF
        [JVERIFICATIONService getAuthorizationWithController:self hide:NO completion:^(NSDictionary *result) {
//            self.loadingImageView.hidden = YES;
            weakSelf.vloginBtn.enabled = YES;

            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"一键登录 result:%@", result.description);
                NSString *token = result[@"loginToken"];
                NSInteger code = [result[@"code"] integerValue];
                if (token) {
                    [JVERIFICATIONService dismissLoginControllerAnimated:YES completion:^{}];
                    [weakSelf verifyLoginToken:token];
                    
                }else if(code != 6002){
                    [JVERIFICATIONService dismissLoginControllerAnimated:YES completion:^{
                    }];

                    NSString *erroMsg = [NSString stringWithFormat:@"获取LoginToken失败code:%@,msg:%@",result[@"code"],result[@"content"]];
                    [SVProgressHUD showErrorWithStatus:erroMsg];
                    [SVProgressHUD dismissWithDelay:1];
                }
            });
        } actionBlock:^(NSInteger type, NSString *content) {
            weakSelf.vloginBtn.enabled = YES;
//            [SVProgressHUD showErrorWithStatus:content];
//            [SVProgressHUD dismissWithDelay:1];
        }];

    }
}

- (IBAction)countLoginAction:(id)sender {
    LoginViewController *vc = [[LoginViewController alloc] init];
    if (self.bannerArray.count > self.currentIndex) {
        vc.model = self.bannerArray[self.currentIndex];
    }
    WEAKSELF
    vc.completion = ^(BOOL isLogin, NSDictionary * _Nonnull options) {
        if (weakSelf.completion) {
            weakSelf.completion(isLogin, options);
        }
    };
    self.navigationController.delegate = vc;
    [self.navigationController pushViewController:vc animated:YES];
}


- (IBAction)closeAction:(id)sender {
    
    [self.navigationController dismissViewControllerAnimated:YES completion:^{
        if (self.completion) {
            self.completion(NO, @{});
        }
    }];
    [[TT_TabbarViewController shareTabbar] setCurrentIndex:TT_TabbarIndexType_Home];
}


- (void)verifyLoginToken:(NSString *)loginToken {
    [self request_vertiLoginWithcode:loginToken];
}

#pragma mark 手机号一键登录
- (void)request_vertiLoginWithcode:(NSString *)code {
    
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:code forKey:@"code"];
    [dic setValue:[TTUserModel sharedObject].installModel.myCode forKey:@"myCode"];

    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Platform,API_VertiLogin];

    WEAKSELF
    [SVProgressHUD showWithStatus:@"正在登录"];
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        [SVProgressHUD dismiss];
        if ([data isKindOfClass:[NSDictionary class]]) {
            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                if ([data[@"data"] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *resultDic = [data valueForKey:@"data"];
                    BOOL isRegister = [[resultDic valueForKey:@"isRegister"] boolValue];
                    if (isRegister) {
                        [OpenInstallSDK reportRegister];
                        [TTUserModel sharedObject].isRegister = YES;
                    }
                    if ([resultDic isKindOfClass:[NSDictionary class]] && [resultDic.allKeys containsObject:@"token"]) {
                        
                        NSString *token = [resultDic valueForKey:@"token"];
                        NSMutableDictionary *user = [resultDic valueForKey:@"user"];
        
                        [[TTUserModel sharedObject].userModelDefault setValue:token forKey:@"TT_token"];
                        
                        BOOL isNewer = [[resultDic valueForKey:@"isNewer"] boolValue];
                        [[TTUserModel sharedObject].userModelDefault setValue:isNewer?@"1":@"0" forKey:@"TT_isNewer"];
                        
                        [[TTUserModel sharedObject].userModelDefault synchronize];
                        [[TTUserModel sharedObject] fillUserModelWithDic:user];
                        
                        if (weakSelf.completion) {
                            weakSelf.completion(YES, resultDic);
                        }
                        
                        [weakSelf.navigationController dismissViewControllerAnimated:YES completion:nil];
                    }
                } else {
                    [SVProgressHUD showErrorWithStatus:@"用户信息异常请联系客服~"];
                    [SVProgressHUD dismissWithDelay:1];
                }
            } else {
                [SVProgressHUD showErrorWithStatus:[data valueForKey:@"message"]];
                [SVProgressHUD dismissWithDelay:1];
            }
        }

    } FailedBlock:^(NSError * _Nonnull error) {

        [SVProgressHUD showErrorWithStatus:@"请求异常"];
        [SVProgressHUD dismissWithDelay:1];
    }];
}

- (UINib *)customCollectionViewCellNibForCycleScrollView:(SDCycleScrollView *)view {
    return [UINib nibWithNibName:@"V_LoginBannerCell" bundle:nil];
}

- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view {
    V_LoginBannerCell *myCell = (V_LoginBannerCell *)cell;
    [myCell.bgImageView setImage:[UIImage imageNamed:self.bannerArray[index].bgImageUrl]];
    [myCell.maskImageView setImage:[UIImage imageNamed:self.bannerArray[index].maskImageUrl]];
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {
    self.currentIndex = index;
}

- (SDCycleScrollView *)bannerView {
    if (!_bannerView) {
        _bannerView = [[SDCycleScrollView alloc] init];
        _bannerView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
        _bannerView.autoScrollTimeInterval = 3;
        _bannerView.backgroundColor = UIColor.clearColor;
        _bannerView.showPageControl = YES;
        _bannerView.pageControlBottomOffset = Bottom_SafeHeight + 150;
        _bannerView.currentPageDotColor = [UIColor.whiteColor colorWithAlphaComponent:1];
        _bannerView.pageDotColor = [UIColor.whiteColor colorWithAlphaComponent:0.5];
        _bannerView.pageControlDotSize = CGSizeMake(8, 8);
        _bannerView.delegate = self;
    }
    return _bannerView;
}

- (NSMutableArray *)configArray {
    
    NSMutableArray *array = @[
        @{@"type": @"_x2",
          @"imgCfgArray":@[@{@"bgImageUrl":@"login_banner1.png",
                             @"maskImageUrl":@"login_mask1.png"},
                           @{@"bgImageUrl":@"login_banner2.png",
                             @"maskImageUrl":@"login_mask2.png"},
                           @{@"bgImageUrl":@"login_banner3.png",
                             @"maskImageUrl":@"login_mask3.png"}]
        },
        @{@"type": @"_x3",
          @"imgCfgArray":@[@{@"bgImageUrl":@"login_banner1.png",
                             @"maskImageUrl":@"login_mask1.png"},
                           @{@"bgImageUrl":@"login_banner2.png",
                             @"maskImageUrl":@"login_mask2.png"},
                           @{@"bgImageUrl":@"login_banner3.png",
                             @"maskImageUrl":@"login_mask3.png"}]
        },
        @{@"type": @"_x4",
          @"imgCfgArray":@[@{@"bgImageUrl":@"login_banner1.png",
                             @"maskImageUrl":@"login_mask1.png"},
                           @{@"bgImageUrl":@"login_banner2.png",
                             @"maskImageUrl":@"login_mask2.png"},
                           @{@"bgImageUrl":@"login_banner3.png",
                             @"maskImageUrl":@"login_mask3.png"}]
        },
        @{@"type": @"_x5",
          @"imgCfgArray":@[@{@"bgImageUrl":@"login_banner1.png",
                             @"maskImageUrl":@"login_mask1.png"},
                           @{@"bgImageUrl":@"login_banner2.png",
                             @"maskImageUrl":@"login_mask2.png"},
                           @{@"bgImageUrl":@"login_banner3.png",
                             @"maskImageUrl":@"login_mask3.png"}]
        },
        @{@"type": @"_x6",
          @"imgCfgArray":@[@{@"bgImageUrl":@"login_banner1.png",
                             @"maskImageUrl":@"login_mask1.png"},
                           @{@"bgImageUrl":@"login_banner2.png",
                             @"maskImageUrl":@"login_mask2.png"},
                           @{@"bgImageUrl":@"login_banner3.png",
                             @"maskImageUrl":@"login_mask3.png"}]
        }
    ].mutableCopy;
    return array;
}

@end
